<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>登录</title>
<jsp:include page="inc.jsp"></jsp:include>
<link href="${pageContext.request.contextPath}/web/css/style.css" rel="stylesheet" type="text/css" />
</head>
<script type="text/javascript" charset="utf-8">

	var key='username';
	var pwd='pwd';
	if(top.location!=self.location){
		top.location=self.location;
	}
		
	$(function() {
		$("#username").focus();
		$("#username").bind('keyup', function(event) {/* 增加回车提交功能 */
			if (event.keyCode == '13') {
				$("#password").focus();
				}
		});
		$("#password").bind('keyup', function(event) {/* 增加回车提交功能 */
			if (event.keyCode == '13') {
/* 				window.open ("${pageContext.request.contextPath}/index.html", "win",  "left=0,top=0,width="+ (screen.availWidth - 10) +",height="+ (screen.availHeight-50) +"resizable=yes,toolbar=no, menubar=no, location=no, status=no");  
 */				login(); 				
				}
		});

		//将cookie的值赋给文本框
		var un=$.cookie(key);
		var pd=$.cookie(pwd);
		if(un!=null&&pd!=null){
			//赋值
			$("#username").val(un);
			$("#password").val(pd);
			//选中
			$("#save").prop("checked",true);
		}
		
	});

	function login(){
		//提交表单之前，对cookie进行保存
		try{
			cookie();
		}catch(e){
			alert(e);
		}
		//if(1==1)return;
		
		$('#loginInputForm').form('submit', {
			url : '${pageContext.request.contextPath}/loginAction!login.html',
			type : "POST",
			success : function(d){
				if(d!='false'){
					$("#error").html(d);
				}else{
					window.location.href='${pageContext.request.contextPath}';
				}
			}
		}); 		
	}
	
	function cookie(){
		
		//checked
		var checkbox=$("#save");
		var rs=checkbox.prop("checked");
		
		var value=$('#username').val();
		var password=$("#password").val();
		
		//记住用户名
		if(rs){
			 $.cookie(key,value);
			 $.cookie(pwd,password);
		}
		//取消记住用户名
		else{
			$.cookie(key,null);
			$.cookie(pwd,null);
		}
		
	}
	
</script>
<body class="loginbg">
<div class="login">
  <div class="content">
	  <form id="loginInputForm" method="post" 
								action="">
		    <div class="logo"><img src="${pageContext.request.contextPath}/web/imgs/logo.gif" width="318" height="87" /></div>
		   
		    <div class="land">
		    	<div ><span id="error" style="color: #F36305"></span></div>
		      <ul>
		        <li>用户名：</li>
		        <li><input id="username" name="username" type="text" class="input easyui-validatebox" data-options="required:true,missingMessage:'请填写用户名'" value=""/></li>
		      </ul>
		      <ul>
		        <li>密&nbsp;&nbsp;码：</li>
		        <li><input id="password" name="password" type="password" class="input easyui-validatebox" data-options="required:true,missingMessage:'请填写密码'"/></li>
		      </ul>
		      <ul>
		      	<li style="text-align: right"><input type="checkbox" id="save"/><label for="save">记住我</label></li>
		      </ul>
		      <ul>
		        <li class="button"><a href="javascript:login();"><img src="${pageContext.request.contextPath}/web/imgs/denglu.jpg" width="96" height="31" /></a></li>
		      </ul>
		    </div>
	    </form>
  </div>
  <div class="copyrights">Copyright @ 2013     <a href="http://www.miitbeian.gov.cn" target="_blank" style="color:#FFFFFF; text-decoration:none;">浙ICP备13002014号-1</a><br/>杭州怀才商贸有限公司 </div>
</div>
</body>
</html>